home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / Extension Shell 1.3 / Sample Extensions / Quadra INIT ƒ / Quadra INIT.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  7.1 KB  |  275 lines  |  [TEXT/R*ch]

  1. /*    NAME:
  2.         Quadra INIT.c 
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant
  6.                 
  7.     DESCRIPTION:
  8.         This file contains a CODE resource to be used as a handler by
  9.         Extension Shell.
  10.  
  11.     ___________________________________________________________________________
  12.  
  13.     VERSION HISTORY:
  14.         (Jan 1994, dg)
  15.             •    First publicly distributed version.
  16.  
  17.  
  18.     ___________________________________________________________________________
  19. */
  20. //=============================================================================
  21. //        Include files                                                                     
  22. //-----------------------------------------------------------------------------
  23. #include <GestaltEqu.h>
  24. #include "ParamBlock.h"
  25. #include "StandaloneCode.h"
  26. #include "ESConstants.h"
  27. #include "Quadra INIT.h"
  28. #include "CodeConstants.h"
  29.  
  30.  
  31.  
  32.  
  33.  
  34. //=============================================================================
  35. //        Private function prototypes                                                                     
  36. //-----------------------------------------------------------------------------
  37. void    main(short theMsg, ESParamBlock *theParamBlock);
  38. void    InitialiseParamBlock(void);
  39. void    InitialiseAddrsTable(void);
  40. void    HandleTheError(void);
  41. void    SetUpIcons(int animDelay, int numIcons, int firstIcon);
  42.  
  43.  
  44.  
  45.  
  46.  
  47. //=============================================================================
  48. //        Global variables                                                                 
  49. //-----------------------------------------------------------------------------
  50. ESParamBlock    *gTheParamBlock;
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. //=============================================================================
  62. //        main : Entry point to our code resource.                                                                 
  63. //-----------------------------------------------------------------------------
  64. //        Note :    Extension Shell communicates with us via a message constant,
  65. //                and a pointer to a structure it owns. Our job is to fill in
  66. //                the details, depending on what it wants us to do. It takes
  67. //                care of the rest.
  68. //-----------------------------------------------------------------------------
  69. void main(short theMsg, ESParamBlock *theParamBlock)
  70. {
  71.  
  72.  
  73.  
  74.  
  75.     // Set up A4 so that we can access our globals, and initialise them.
  76.     GetGlobals();
  77.     gTheParamBlock = theParamBlock;
  78.  
  79.  
  80.  
  81.     // Case out on what we have to do
  82.     switch(theMsg) {
  83.         case kInitialiseParamBlock:
  84.              InitialiseParamBlock();
  85.              break;
  86.              
  87.         case kInitialiseAddrsTable:
  88.              InitialiseAddrsTable();
  89.              break;
  90.  
  91.         case kHandleError:
  92.              HandleTheError();
  93.              break;
  94.     
  95.         default:
  96.              ;
  97.     }
  98.  
  99.  
  100.  
  101.     // Restore A4.
  102.     UngetGlobals();
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. //=============================================================================
  115. //        InitialiseParamBlock : Initialises the ParamBlock.                                                                 
  116. //-----------------------------------------------------------------------------
  117. //        Note :    We have three things we want to do:
  118. //                    • Check to see if we can still run
  119. //                    • Set up the icons we want to display
  120. //                    • Set up the code we want installed.
  121. //-----------------------------------------------------------------------------
  122. void InitialiseParamBlock(void)
  123. {    int        i;
  124.  
  125.  
  126.  
  127.  
  128.     // Check for System 7. We depend on having System 7, and won't
  129.     // run if we don't have it. We beep, and post a relevent
  130.     // error message.
  131.     if (gTheParamBlock->systemVersion < 0x0700)
  132.         {
  133.         gTheParamBlock->beepNow                = true;
  134.         gTheParamBlock->postError            = true;
  135.         gTheParamBlock->errorStringsID        = kErrorStrings;
  136.         gTheParamBlock->errorStringIndex    = kNeedSystemSeven;
  137.  
  138.  
  139.         // Icon details
  140.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  141.         }
  142.     
  143.     
  144.     
  145.     // If a shift key, or the mouse button, is down, we don't load either.
  146.     // We don't post an error, but just show our disabled icon(s).
  147.     else if ((*gTheParamBlock->UserForcedDisable)(kShiftKey, true))
  148.         {
  149.         // Icon details
  150.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  151.         }
  152.     
  153.     
  154.     
  155.     // Otherwise, we're allowed to run so we show our icon(s) as normal,
  156.     // and install the code we have to install.
  157.     else
  158.         {
  159.         // Icon details
  160.         SetUpIcons(kEnabledAnimDelay, kMyNumEnabledIcons, kMyFirstEnabledIcon);
  161.         
  162.         
  163.         // We install one code resource, and use an address table.
  164.         gTheParamBlock->installAddressTable        = true;
  165.         gTheParamBlock->addressTableSelector    = kMacTypeAddressTable;
  166.         gTheParamBlock->numCodeResources        = 1;
  167.  
  168.  
  169.         // Details for a replacement Gestalt selector.
  170.         // Details for a Gestalt selector
  171.         gTheParamBlock->theCodeResources[kMacType].resType        = kMacTypeSelectorResType;
  172.         gTheParamBlock->theCodeResources[kMacType].resID        = kMacTypeSelectorResID;
  173.         gTheParamBlock->theCodeResources[kMacType].codeType        = kGestaltSelectorType;
  174.         gTheParamBlock->theCodeResources[kMacType].theCodeThing.theGestaltSelector.theSelector = kMacTypeSelectorType;
  175.         gTheParamBlock->theCodeResources[kMacType].theCodeThing.theGestaltSelector.overwriteExistingSelector = true;
  176.         }
  177. }
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188. //=============================================================================
  189. //        InitialiseAddrsTable : Initialise the address table.                                                     
  190. //-----------------------------------------------------------------------------
  191. //        Note :    If we are being used in a Control Panel, we will probably have
  192. //                implemented the address table code with a custom code resource
  193. //                that returns a structure with an address table embedded at the
  194. //                start. This function's job is to correctly initialise the
  195. //                extended fields of that structure. If we're not using a
  196. //                (custom) address table then we don't do anything.
  197. //
  198. //                The message for this routine will only arrive if we've
  199. //                requested an address table.
  200. //-----------------------------------------------------------------------------
  201. void InitialiseAddrsTable(void)
  202. {
  203.  
  204.  
  205.  
  206. }
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217. //=============================================================================
  218. //        HandleTheError : Handle any errors                                                             
  219. //-----------------------------------------------------------------------------
  220. //        Note :    If any error occurs, we beep, post an error, and remove our
  221. //                code. We also have to reset the icon details to show our
  222. //                disabled icons.
  223. //-----------------------------------------------------------------------------
  224. void HandleTheError(void)
  225. {
  226.  
  227.  
  228.  
  229.  
  230.     // General error handling settings
  231.     gTheParamBlock->removeInstalledCode    = true;
  232.     gTheParamBlock->beepNow                = true;
  233.     gTheParamBlock->postError            = true;
  234.     gTheParamBlock->errorStringsID        = kErrorStrings;
  235.  
  236.  
  237.  
  238.     // Icon details
  239.     SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  240.  
  241.  
  242.  
  243.     // Just give a general error.
  244.     gTheParamBlock->errorStringIndex = kUnknownError;
  245. }
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256. //=============================================================================
  257. //        SetUpIcons : Set up our icons accordingly.                                                         
  258. //-----------------------------------------------------------------------------
  259. //        Note :    We are passed in the resource ID of the first icon, the number
  260. //                of icons, and a delay for animation. We just fill in the fields
  261. //                in the paramBlock.
  262. //-----------------------------------------------------------------------------
  263. void SetUpIcons(int animDelay, int numIcons, int firstIcon)
  264. {    int        i;
  265.  
  266.  
  267.  
  268.  
  269.     // Fill in the fields
  270.     gTheParamBlock->animationDelay    = animDelay;
  271.     gTheParamBlock->numIcons        = numIcons;
  272.     for (i = 1; i <= numIcons; i++)
  273.         gTheParamBlock->theIcons[i] = firstIcon + i - 1;
  274. }
  275.